
type bsmt=
    Ent of int
    |Rts of int
    |Jsr of int
	|Push of string
    |Pushal of int*string
    |Pushag of int*string
    |Lfp of int
    |Lod of int
    |LoLkwb of int*string
    |GlLkwb of int*string
    |LoJpwb of int*string
    |GlJpwb of int*string
	|Lowbt of int*string*string    (*local title write back*)
	|Glwbt of int*string*string    (*global title write back*)

	|Lowba of int*int (*local answers write back*)
	|Glwba of int*int (*global answers write back*)
	|Lotwbt of int*int (*local text length write back*)
	|Gltwbt of int*int (*global text lenght write back*)
	|Loqswb of int*int (*local question set write back*)
	
	|Loquetrace of int (*trace the qeuestion locally*)
 
	|Loshow of int (*show the local questionset*)

    |Hlt
    
type prog={
      num_globals : int;
      text : bsmt array;
}

let string_of_stmt = function
    |Ent(i)->"ent" ^ string_of_int i
    |Lfp (i) ->"lfp" ^ string_of_int i
    |Lod(i)-> "Lod" ^ string_of_int i
    |Rts(i) -> "Rts" ^ string_of_int i
    |Jsr(i)->"Jsr"^ string_of_int i
    |Push(i)->"Push" ^ i
    |Pushal (i, j)->"Pushal" ^ string_of_int i ^"  "^ j
    |Pushag (i,j)-> "Pushag" ^ string_of_int i ^"  "^ j
    |LoLkwb(i,j) -> "LoLkwb" ^ string_of_int i ^ "  " ^j
    |GlLkwb(i, j)-> "GlLkwb" ^ string_of_int i^ "  " ^ j
    |LoJpwb(i,j)-> "LoJpwb" ^ string_of_int i ^ " " ^ j
    |GlJpwb(i,j)-> "GlJpwb" ^ string_of_int i^ " "^ j
    |Lowbt(i,j,k)->"Lowbt" ^ string_of_int i ^ " "^j ^" "^ k
    |Glwbt(i,j,k)->"Glwbt" ^ string_of_int i ^ " "^ j ^" "^ k
    |Lowba(i,j)->"Lowwba" ^ string_of_int i ^ string_of_int j 
    |Glwba(i,j)->"Glwba" ^ string_of_int i ^ string_of_int j 
    |Lotwbt(i,j)->"Lotwbt" ^ string_of_int i ^ string_of_int j
    |Gltwbt (i, j)-> "Gltwbt" ^ string_of_int i ^ string_of_int j
    |Loqswb(i,j)->"Loqswb" ^ string_of_int i ^ string_of_int j
 
    |Loquetrace(i)-> "Loquetrace" ^ string_of_int i
    
    |Loshow(i)->"Loshow" ^ string_of_int i
  
    |Hlt->"Hlt"

let string_of_prog p =
  string_of_int p.num_globals ^ " global variables\n" ^
  let funca = Array.mapi
      (fun i s -> string_of_int i ^ " " ^ string_of_stmt s) p.text
  in String.concat "\n" (Array.to_list funca)
